import requests as re
import json
#请求的API
url='https://www.hhlqilongzhu.cn/api/ximalaya/ximalaya.php'
#请求参数
params= {
        "albumId": 81936254,  # 搜索的专辑ID
        "pageNum": 1,  # 页码
        "pageSize": 30  # 每页结果数量
    }
#请求头
headers={
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
    "Referer": "https://www.ximalaya.com/",
    "Content-Type": "application/json",
}
resp=re.get(url,params=params, headers=headers)#发起请求
if(resp.status_code==200):
    # 解析响应的JSON数据
    data = resp.json()
    try:
        with open('喜马拉雅.txt', 'w', encoding='utf-8') as f:
            json.dump(data, f, ensure_ascii=False, indent=4)
    except IOError as e:
        print(f"保存文件失败: {e}")